package com.ruoyi.eservice.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.eservice.service.IDictService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.eservice.pojo.entity.Cases;
import com.ruoyi.eservice.service.ICasesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病例详情Controller
 *
 * @author fancheng
 * @date 2022-11-10
 */
@RestController
@RequestMapping("/einfo/cases")
public class CasesController extends BaseController
{
    @Autowired
    private ICasesService casesService;

    @Autowired
    private IDictService dictService;

    /**
     * 根据名字查询其中区域数据
     * @param areaname  地区的名字
     * @return
     */
    @GetMapping("/areaname")
    public AjaxResult areaCases(@RequestParam("areaname") String areaname){


        return casesService.getDictByName(areaname);
    }


    /**
     * 查询病例详情列表
     */
    @PreAuthorize("@ss.hasPermi('einfo:cases:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cases cases)
    {
        startPage();
        List<Cases> list = casesService.selectCasesList(cases);
        return getDataTable(list);
    }

    /**
     * 导出病例详情列表
     */
    @PreAuthorize("@ss.hasPermi('einfo:cases:export')")
    @Log(title = "病例详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cases cases)
    {
        List<Cases> list = casesService.selectCasesList(cases);
        ExcelUtil<Cases> util = new ExcelUtil<Cases>(Cases.class);
        util.exportExcel(response, list, "病例详情数据");
    }

    /**
     * 获取病例详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('einfo:cases:query')")
    @GetMapping(value = "/{casesId}")
    public AjaxResult getInfo(@PathVariable("casesId") Long casesId)
    {
        return AjaxResult.success(casesService.selectCasesByCasesId(casesId));
    }

    /**
     * 新增病例详情
     */
    @PreAuthorize("@ss.hasPermi('einfo:cases:add')")
    @Log(title = "病例详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cases cases)
    {
        return toAjax(casesService.insertCases(cases));
    }

    /**
     * 修改病例详情
     */
    @PreAuthorize("@ss.hasPermi('einfo:cases:edit')")
    @Log(title = "病例详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cases cases)
    {
        return toAjax(casesService.updateCases(cases));
    }

    /**
     * 删除病例详情
     */
    @PreAuthorize("@ss.hasPermi('einfo:cases:remove')")
    @Log(title = "病例详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{casesIds}")
    public AjaxResult remove(@PathVariable Long[] casesIds)
    {
        return toAjax(casesService.deleteCasesByCasesIds(casesIds));
    }
}
